package com.szcatic.ework.listener;

import javax.servlet.http.HttpSessionAttributeListener;
import javax.servlet.http.HttpSessionBindingEvent;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;

import org.springframework.web.context.ContextLoader;

import com.szcatic.ework.service.login.LoginService;
import com.szcatic.ework.vo.other.LoginInfo;

public class OnlineSessionListener implements HttpSessionListener,HttpSessionAttributeListener{
	
	@Override
	public void sessionCreated(HttpSessionEvent se) {
		
		System.out.println("session create");
		
	}

	@Override
	public void sessionDestroyed(HttpSessionEvent se) {
		
		LoginService loginService = ContextLoader.getCurrentWebApplicationContext().getBean(com.szcatic.ework.service.login.LoginService.class);
		LoginInfo loginInfo = new LoginInfo();
		loginInfo.setSessionId(se.getSession().getId());
		loginService.updateLoginInfo(loginInfo);
		System.out.println("session destroy");
		
	}

	@Override
	public void attributeAdded(HttpSessionBindingEvent event) {
		
	}

	@Override
	public void attributeRemoved(HttpSessionBindingEvent event) {
		
	}

	@Override
	public void attributeReplaced(HttpSessionBindingEvent event) {
		
	}

}
